/*
 *  SoundGeneratorTester.cpp
 *  SoundController0002
 *
 *  Created by jiro on 11/02/23.
 *  Copyright 2011 jiro music. All rights reserved.
 *
 */

#include "SoundGeneratorTester.h"
#include "../SoundGenerator.h"
#include "CustomAssert.h"

namespace sc 
{

	void SoundGeneratorTester::TestAll()
	{
		Test_Generate_001();
		
		Test_Generate_002();

		Test_Generate_003();
	}

	void SoundGeneratorTester::Test_Generate_001()
	{
		std::vector< NoteInfo > infos( 2 );
		infos[ 0 ].frequency = 92.4986;
		infos[ 0 ].duration = 3.3333;
		infos[ 0 ].dynamics = 0.625;

		infos[ 1 ].frequency = 138.591;
		infos[ 1 ].duration = 3.3333;
		infos[ 1 ].dynamics = 0.625;

		std::vector< const SoundElement32* > elements = SoundGenerator::Generate( infos );

		AssertNotEqual( elements[ 0 ], elements[ 1 ] );
	}

	void SoundGeneratorTester::Test_Generate_002()
	{
		std::vector< NoteInfo > infos( 2 );
		infos[ 0 ] = NoteInfo( 207.652, 0.4, 0.5 );
		infos[ 1 ] = NoteInfo( 440, 0.4, 0.5 );

		std::vector< const SoundElement32* > elements = SoundGenerator::Generate( infos );

		AssertNotEqual( elements[ 0 ], elements[ 1 ] );
	}

	void SoundGeneratorTester::Test_Generate_003()
	{
		std::vector< NoteInfo > infos( 7 );
		infos[ 0 ] = NoteInfo( 207.652, 0.4, 0.5 );
		infos[ 1 ] = NoteInfo( 220, 0.4, 0.541667 );
		infos[ 2 ] = NoteInfo( 329.628, 0.4, 0.583333 );
		infos[ 3 ] = NoteInfo( 311.127, 0.4, 0.625 );
		infos[ 4 ] = NoteInfo( 369.994, 0.4, 0.666667 );
		infos[ 5 ] = NoteInfo( 415.305, 0.4, 0.708333 );
		infos[ 6 ] = NoteInfo( 440, 0.4, 0.5 );

		std::vector< const SoundElement32* > elements = SoundGenerator::Generate( infos );
		for ( int i = 0; i < elements.size(); i++ ) {
			for ( int j = i + 1; j < elements.size(); j++ ) {
				stringstream sstr;
				sstr << i << " " << j;
				AssertEqualWithMessage( * elements[ i ] != * elements[ j ], true, sstr.str() ); 
			}
		}
	}
}